From 7b431bed513db3318811698029304d81e5831ab3 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Sun, 22 Jul 2018 22:35:58 +0100 Subject: cIsThread: Reset m_ShouldTerminate after the thread has stopped (#4258) This allows threads to be restarted after stopping. Fixes #4257 --- src/ChunkSender.cpp | 12 +----------- src/ChunkSender.h | 2 -- src/Generating/ChunkGenerator.cpp | 2 +- src/LightingThread.cpp | 2 +- src/OSSupport/IsThread.cpp | 10 ++-------- src/Protocol/Authenticator.cpp | 3 +-- src/WorldStorage/WorldStorage.cpp | 2 +- 7 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/ChunkSender.cpp b/src/ChunkSender.cpp index 60f9d8c68..aa51ed4ed 100644 --- a/src/ChunkSender.cpp +++ b/src/ChunkSender.cpp @@ -79,21 +79,11 @@ cChunkSender::~cChunkSender() -bool cChunkSender::Start() -{ - m_ShouldTerminate = false; - return super::Start(); -} - - - - - void cChunkSender::Stop(void) { m_ShouldTerminate = true; m_evtQueue.Set(); - Wait(); + super::Stop(); } diff --git a/src/ChunkSender.h b/src/ChunkSender.h index a17dfcab2..c5702d7b3 100644 --- a/src/ChunkSender.h +++ b/src/ChunkSender.h @@ -67,8 +67,6 @@ public: }; - bool Start(); - void Stop(void); /** Queues a chunk to be sent to a specific client */ diff --git a/src/Generating/ChunkGenerator.cpp b/src/Generating/ChunkGenerator.cpp index e0fee5bd0..3ac128c46 100644 --- a/src/Generating/ChunkGenerator.cpp +++ b/src/Generating/ChunkGenerator.cpp @@ -98,7 +98,7 @@ void cChunkGenerator::Stop(void) m_ShouldTerminate = true; m_Event.Set(); m_evtRemoved.Set(); // Wake up anybody waiting for empty queue - Wait(); + super::Stop(); delete m_Generator; m_Generator = nullptr; diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index ccefdfef2..c83589965 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -140,7 +140,7 @@ void cLightingThread::Stop(void) m_ShouldTerminate = true; m_evtItemAdded.Set(); - Wait(); + super::Stop(); } diff --git a/src/OSSupport/IsThread.cpp b/src/OSSupport/IsThread.cpp index 3f75951ba..d60d0d9eb 100644 --- a/src/OSSupport/IsThread.cpp +++ b/src/OSSupport/IsThread.cpp @@ -60,8 +60,7 @@ cIsThread::cIsThread(const AString & a_ThreadName) : cIsThread::~cIsThread() { - m_ShouldTerminate = true; - Wait(); + Stop(); } @@ -110,14 +109,9 @@ bool cIsThread::Start(void) void cIsThread::Stop(void) { - if (!m_Thread.joinable()) - { - // The thread hasn't been started or has already been joined - return; - } - m_ShouldTerminate = true; Wait(); + m_ShouldTerminate = false; } diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index 445a3dff5..da4685635 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -77,7 +77,6 @@ void cAuthenticator::Authenticate(int a_ClientID, const AString & a_UserName, co void cAuthenticator::Start(cSettingsRepositoryInterface & a_Settings) { ReadSettings(a_Settings); - m_ShouldTerminate = false; super::Start(); } @@ -89,7 +88,7 @@ void cAuthenticator::Stop(void) { m_ShouldTerminate = true; m_QueueNonempty.Set(); - Wait(); + super::Stop(); } diff --git a/src/WorldStorage/WorldStorage.cpp b/src/WorldStorage/WorldStorage.cpp index 7be710c29..a3aff0749 100644 --- a/src/WorldStorage/WorldStorage.cpp +++ b/src/WorldStorage/WorldStorage.cpp @@ -94,7 +94,7 @@ void cWorldStorage::WaitForFinish(void) // Wait for the thread to finish: m_ShouldTerminate = true; m_Event.Set(); // Wake up the thread if waiting - super::Wait(); + super::Stop(); LOGD("World storage thread finished"); } -- cgit v1.2.3